package com.yuqing.sentimentapp.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.LinearLayout;

import com.linkface.baselibrary.utils.DensityUtil;
import com.yuqing.sentimentapp.utils.DisplayUtil;

public class MyLinearLayout extends LinearLayout {
    private int width;
    private int height;

    public MyLinearLayout(Context context) {
        super(context);
        initWidth();
    }

    public MyLinearLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initWidth();
    }

    public MyLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initWidth();
    }

    private void initWidth() {
        width = (DisplayUtil.getScreenWidth(getContext()) - DensityUtil.dip2px(getContext(), 20)) / 3;
        height = width;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        setMeasuredDimension(width, height);
    }
}
